package com.yanqu.road.dao.impl.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.config.winery.WineryConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class WineryConfigDaoImpl extends TempDao {
    private static String getWineryConfigSql = "select * from `t_p_winery` ORDER BY `id` ASC";
    public List<WineryConfig> getWineryConfigList() {
        List<WineryConfig> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getConfigDb());
            call = getDb().getConnection().prepareCall(getWineryConfigSql);
            rs = call.executeQuery();
            while (rs.next()) {
                WineryConfig wineryConfig = new WineryConfig();
                wineryConfig.setId(rs.getInt("id"));
                wineryConfig.setName(rs.getString("name"));
                wineryConfig.setType(rs.getInt("type"));
                wineryConfig.setUpgrade(rs.getInt("upgrade"));
                wineryConfig.setSkills(rs.getString("skills"));
                wineryConfig.parse();
                list.add(wineryConfig);
            }
            return list;
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return null;
    }

}
